<?php
require $_SERVER["DOCUMENT_ROOT"] . "/aonce_connect.php";

/*
 * Primer capa de validacion de obtencion de datos de artista
 * Metodos POST & GET cubuertos
 */

$artista = isset($_GET["artista"]) ? $_GET["artista"] : NULL;
if($artista == NULL)
	$artista = isset($_POST["artista"]) ? $_POST["artista"] : NULL;

$serie = isset($_GET["serie"]) ? $_GET["serie"] : NULL;
if($serie == NULL)
	$serie = isset($_POST["serie"]) ? $_POST["serie"] : NULL;

if($serie == NULL){
	$err_msg = "Serie no econtrada";
//	redirect_error($msg);
	printf($err_msg);
}

/*
 * Queries de obtenci'on de informaci'on del artista, sus series y fotos
 */
$artista_fields = "nombreartista AS nombre, bioartista AS bio, cvartista AS cv, fotoartista AS foto";
$artista_query = "SELECT $artista_fields FROM artista WHERE idartista=$artista LIMIT 1;";
//echo $artista_query;

$serie_fields = "idserie, nombreserie AS nombre";
$serie_query = "SELECT $serie_fields FROM serie WHERE artista=$artista ORDER BY idserie DESC;";
//echo $serie_query;

$picsser_fields = "idpicsser, serie, titulopicsser AS titulo, yearpicsser AS year, materialpicsser AS material, medidaspicsser AS medidas, fotopicsser AS foto, orientacionpicsser AS hv";
$picsser_query = "SELECT $picsser_fields FROM picsser WHERE serie=$serie LIMIT 6;";
//echo $picsser_query;

/*
 * Conexion a DB y ejecuci'on de queries
 */
$link = conecta();
$artista_result = $link->query($artista_query);
$serie_nums = $link->query($serie_query);
$serie_result = $link->query($serie_query);
$picsser_result = $link->query($picsser_query);
/*
$artista_result = mysql_query($artista_query);
$serie_nums = mysql_query($serie_query);
$serie_result = mysql_query($serie_query);
$picsser_result = mysql_query($picsser_query);
//var_dump($link);
 */
desconecta($link);

/*
 * Asociaci'on de datos de artista y serie con variables
 */
$artista_data = $artista_result->fetch_assoc();
//$artista_data = mysql_fetch_assoc($artista_result);
//var_dump($artista_data);
?>
<!--Force IE6 into quirks mode with this comment tag-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Alternativa Once</title>
<link href="styleIndex.css" rel="stylesheet" type="text/css" />
<link href="styleArtista.css" rel="stylesheet" type="text/css" />

</head>
<body>
<script type="text/javascript">
function setMainPic(pic_id){
//		alert(pic_id);
		switch(pic_id){
		//alert(pic_id);
<?php
$thumbsArray_str="";
//	var_dump($fotosArray);
	while($picsser_data = $picsser_result->fetch_assoc()){
//	while($picsser_data = mysql_fetch_assoc($picsser_result)){
			printf("\tcase %1\$d:\n", $picsser_data["idpicsser"]);
			if($thumbsArray_str=="")
			$firstPic = $picsser_data["idpicsser"];
//			printf("\talert(\"IINCASE\");");
				printf("\t\tdocument.getElementById(\"mainPic\").src=\"uploads/%s\";\n", $picsser_data["foto"]);
				printf("\t\tdocument.getElementById(\"title\").innerHTML=\"%s\";\n", $picsser_data["titulo"]);
				printf("\t\tdocument.getElementById(\"year\").innerHTML=\"%d\";\n", $picsser_data["year"]);
				printf("\t\tdocument.getElementById(\"material\").innerHTML=\"%s\";\n", $picsser_data["material"]);
				printf("\t\tdocument.getElementById(\"measure\").innerHTML=\"%s\";\n", $picsser_data["medidas"]);
//			printf("\talert(\"IOUTCASE\");");
  				$thumbsArray_str .= sprintf("\t\t<div class=\"thumbnail\"><img src=\"thumbs/%s\" onclick=\"setMainPic(%d);\"></div>\n", $picsser_data["foto"], $picsser_data["idpicsser"]);
		printf("\tbreak;\n");
			}
?>
		default:
//				alert("ouh!");
			break;
		}
}
function bio_cv(opcion){
	switch(opcion){
	default:
	case 'bio':
			document.getElementById("bio").style.display='';
			document.getElementById("bio_op").className = 'selected';
			document.getElementById("cv").style.display='none';
			document.getElementById("cv_op").className='';
		break;	
	case 'cv':
			document.getElementById("cv").style.display='';
			document.getElementById("cv_op").className='selected';
			document.getElementById("bio").style.display='none';
			document.getElementById("bio_op").className='';
		break;	
	}
}
</script>
<div id="framecontent">
<div class="seccioninterior">

<?php require "foot.php";?>  

</div>
</div>

<div id="maincontent">
<?php require "head.php";?>
<div class="cuadroListaObrasArtista">
<div class="seccioninterior seccioninteriortop">
<div id="menuobras" style="float:left; padding-top:60px; font-size:10px; ">
  <ul>
<?php
while($serie_data = $serie_result->fetch_assoc()){
//while($serie_data = mysql_fetch_assoc($serie_result)){
		if($serie_data["idserie"]==$serie)
			printf("\t<li class=\"selected\" onClick=\"chgMainPic(%d);\" onMouseOver='this.style.backgroundColor='#f3f3f3';' onMouseOut='this.style.backgroundColor=''; '><a href=\"artista.php?artista=$artista&serie=%1\$d\">%s</a></li>\n", $serie_data["idserie"], $serie_data["nombre"]);				 
		else
			printf("\t<li onClick=\"chgMainPic(%d);\" onMouseOver='this.style.backgroundColor='#f3f3f3';' onMouseOut='this.style.backgroundColor=''; '><a href=\"artista.php?artista=$artista&serie=%1\$d\">%s</a></li>\n", $serie_data["idserie"], $serie_data["nombre"]);
	}
 ?>
  </ul>  
</div>
</div>

<div class="seccioninterior" style="width:390px; margin-top:0">
<div style="float: left">
<div id="navcontainer">
<ul id="menutag">
   <li id="bio_op" class="selected" onClick="bio_cv('bio');"><a style="cursor:pointer">BIOGRAFIA</a></li>
   <li id="cv_op" style="border:0" onClick="bio_cv('cv');"><a style="cursor:pointer">CURRICULUM</a></li>                                                    
</ul> 
</div>  
		<div id="bio" style="font-size:10px;">
		<?php
			echo $artista_data["bio"];
		?>
		</div>
		<div id="cv" style="font-size:10px; display:none;">
		<?php
			echo $artista_data["cv"];
		?>
		</div>
</div>
</div>
</div>

<div style="">
<div class="cuadroDerechoArtista">
<h1 class="tituloArtista"><?php echo $artista_data["nombre"];?></h1>
<div class="cuadroDerechoArtistaGr_0">
  <img id="mainPic" src="" style="border:10px solid #f3f3f3"/>
</div>

<div class="detallesobra">
  <div id="title"></div>
  <div id="year"></div>
  <div id="material"></div>
  <div id="measure"></div>
  <!-- <div id="">Photo. Stephen White</div> -->
</div>

<div id="thumbnailboxvertical">
<?php
	echo $thumbsArray_str;
?>
</div>

</div>
</div>
</div>
<script language="Javascript">
<?php
printf ("setMainPic(%d);\n", $firstPic);
?>
</script>

</body>
</html>
